#include "stdafx.h"
#include "Exports.h"


MEMMAN_API void MmInitialize()
{
	_manager = new CMemMan();
}

MEMMAN_API void MmDeInitialize()
{
	if(_manager)
	{
		delete _manager;
		_manager = NULL;
	}
}

MEMMAN_API void MmReInitialize()
{
	MmDeInitialize();
	MmInitialize();
}

MEMMAN_API bool MmIsInitialized()
{
#pragma warning (disable: 4800)
	retbool _manager;
#pragma warning (default: 4800)
}

MEMMAN_API unsigned GetThreadEventsCount(unsigned threadIdx)
 {
	return _manager->GetEventsCountForThread(threadIdx);
 }

MEMMAN_API unsigned GetThreadIndexForId(short threadId)
 {
	 return _manager->GetThreadIndex(threadId);
 }

MEMMAN_API short GetThreadIdForIndex(unsigned threadIdx)
 {
	return _manager->GetTidForIndex(threadIdx);
 }

MEMMAN_API char* GetEventTime(unsigned threadIdx, unsigned eventIdx)
{
	return _manager->GetEventData(threadIdx, eventIdx, CMemMan::Time);
}

MEMMAN_API char GetEventType(unsigned threadIdx, unsigned eventIdx)
{
	return (char)(_manager->GetEventData(threadIdx, eventIdx, CMemMan::Type));
}

MEMMAN_API char* GetEventService(unsigned threadIdx, unsigned eventIdx)
{
	return _manager->GetEventData(threadIdx, eventIdx, CMemMan::Service);
}

MEMMAN_API char* GetEventMessage(unsigned threadIdx, unsigned eventIdx)
{
	return _manager->GetEventData(threadIdx, eventIdx, CMemMan::Message);
}

MEMMAN_API void GetEventMessageEx(unsigned threadIdx, unsigned eventIdx, char* outBuffer)
{
	_manager->ExpandEventMessage(GetEventMessage(threadIdx, eventIdx), outBuffer);
}

MEMMAN_API unsigned GetThreadsCountTotal()
{
	return _manager->GetThreadsCount();
}

 MEMMAN_API void AddString(LPCSTR data)
 {
	 _manager->PushLine((char*)data);
 }

 MEMMAN_API unsigned AddBlock(LPSTR data)
 {
	return _manager->PushBulk((char*)data);
 }

 MEMMAN_API unsigned ParseBack(LPCSTR data, unsigned size)
 {
	 char* ptr = (char*)data + size - 2;
	 char* ptrCopy = ptr;
	 while (*ptr && *ptr != 10)
		 ptr--;
#ifdef _X64
	 return (unsigned)(ptrCopy - ptr);
#else
	 return ptrCopy - ptr;
#endif
 }